#!/usr/bin/env bash

VERSION="20120823"
MAXARG=1
CURRENDIR=`pwd`

function usage
{
    echo ""
    echo "CPHW dump re-package builder $VERSION"
    echo "Usage: $0 <zipped CPHW dump>"
    echo "e.g:    $0 19089_CXP_902_0643_P10A0020.zip"
    echo ""
    exit 1;
}
          

function check_errs
{
   # Para #1 is the return code
   # Para #2 is text to display on failure.
   if [ "${1}" -ne "0" ]; then
       echo "ERROR: ${1} : ${2}"
   fi 
   return "${1}"
}


function validate_argument
{
   local arg="$1"
   if [ "$#" -gt "$MAXARG" ] || [ "$#" -eq 0 ]; then
       usage;
   fi
   if [ "$arg" = "" ]; then
       echo "Invalid file name!"
       usage;
   fi   
}          

function is_zip_file
{
   local arg=${1}
   if [[ ! -f "$arg" ]]; then 
      continue; 
   fi
   zipinfo "$arg" > /dev/null
   retval=$?
   if [ "$retval" -eq 0 ]; then
       echo "$1 is zip file"
       return 0
   else
       echo "Invalid zip file"
       return 1
   fi
}

echo "Number of arguments passed: $#"
echo "Current dir=${CURRENDIR}"

validate_argument $1
check_errs $? "Zip file incorrect!"
is_zip_file $1
check_errs $? ""

          

